using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for RadioButtonListHelper
/// </summary>
public class RadioButtonListHelper
{
    public void FillDataTableToRadioButtonList(
    DataTable dataTable,
    RadioButtonList radioButtonList,
    string displayMember,
    string valueMember,
    string selectedValue)
    {
                 
        if (dataTable != null)
        {
            radioButtonList.DataSource = dataTable;
            radioButtonList.DataTextField = displayMember;
            radioButtonList.DataValueField = valueMember;
        }
        else
            radioButtonList.DataSource = null;
        radioButtonList.DataBind(); 
        if (selectedValue != "")
            radioButtonList.SelectedValue = selectedValue;
        
    }
    public void FillDataTableToRadioButtonList(
    DataTable dataTable,
    RadioButtonList radioButtonList,
    string firstDisplayMember,
    string firstValueMember,
    string displayMember,
    string valueMember,
    string selectedValue)
    {                 
        if (dataTable != null)
        {
            if (firstDisplayMember != "")
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow[0] = firstValueMember;
                dataRow[1] = firstDisplayMember ;
                dataTable.Rows.InsertAt(dataRow, 0);
            }
            radioButtonList.DataTextField = displayMember;
            radioButtonList.DataValueField = valueMember;
            radioButtonList.DataSource = dataTable;
            radioButtonList.DataBind();
            if (selectedValue != "")
                radioButtonList.SelectedValue = selectedValue;
        }
        else
        {
            radioButtonList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }

        
    }
    
}
